package com.ktjy.controller;


import com.ktjy.entity.Livecommerce;
import com.ktjy.service.LivecommerceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class LivecommerceController {
    @Autowired
    private LivecommerceService livecommerceService;

    @GetMapping("/select")
    public String queryAndRedirect(Model model) {
        List<Livecommerce> list = livecommerceService.select();
        model.addAttribute("list", list);
        return "select";
    }

    @RequestMapping("/detail")
    public String detail(@RequestParam("id") Integer id, Model model) {
        Livecommerce livecommerce = livecommerceService.selectListId(id);
        model.addAttribute("sq", livecommerce);
        return "detail";
    }

    @RequestMapping(value = "/add")
    public String add(){
        return "add";
    }

    @RequestMapping(value = "/save")
    public String save(Livecommerce livecommerce, Model model){
        int count = livecommerceService.add(livecommerce);
        if(count > 0){
            model.addAttribute("add",count);
        }else {
            model.addAttribute("add",0);
        }
        return null;
    }



}
